import java.util.Stack;

public class QueueBy2Stack {

    private Stack<Integer> s1 = new Stack<>();
    private Stack<Integer> s2 = new Stack<>();

    //入队 入队的元素都进入到s1
    public boolean offer(int data){
        s1.push(data);
        return true;
    }


    //出队 s1的元素都pop到s2中 s2再pop的就是队首元素
    public int poll(){
        if(empty()){
            throw new EmptyExeception("空队列！");
        }
        if(s2.empty()) {
            int length = s1.size();
            for (int i = 0; i < length; i++) {
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    //获取队首元素
    public int getHead(){
        if(s2.empty()) {
            int length = s1.size();
            for (int i = 0; i < length; i++) {
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    //判空
    public boolean empty(){
        return s1.empty() && s2.empty();
    }
}
